module map2D {
	export class DirectionType {
		public static NONE:number = -1;
		public static UP:number = 0;
		public static RIGHT_UP:number = 1;
		public static RIGHT:number = 2;
		public static RIGHT_DOWN:number = 3;
		public static DOWN:number = 4;
		public static LEFT_DOWN:number = 5;
		public static LEFT:number = 6;
		public static LEFT_UP:number = 7;
		public static angleArray:number[] = [
			-Math.PI / 2,
			-Math.PI / 4,
			0,
			Math.PI / 4,
			Math.PI / 2,
			Math.PI / 4 * 3,
			Math.PI,
			-Math.PI / 4 * 3];
		/**获取角度对应的状态
		 * @param agl 弧度值
		 * @param directionMode 方向模式 1 8个方向 2 4个方向 参考DirectionMode常量
		 * @param initDir 初始角度
		 * @return 状态值	参考DirectionType常量
		*/
		public static getDirectorSts(agl:number,directionMode:number=1,initDir:number=0):number
		{
			if(agl < 0)
				agl += GYLite.MathConst.DOUBLE_PI;
			agl = agl % GYLite.MathConst.DOUBLE_PI;
			let dir:number;
			let pi_p:number
			if(directionMode == 1)
			{
				pi_p = Math.PI / 8;
				if(agl < Math.PI / 8 || agl > pi_p * 15)
					dir = DirectionType.RIGHT;			
				else if(agl < pi_p * 3)
					dir = DirectionType.RIGHT_DOWN;
				else if(agl < pi_p * 5)
					dir = DirectionType.DOWN;
				else if(agl < pi_p * 7)
					dir = DirectionType.LEFT_DOWN;
				else if(agl < pi_p * 9)
					dir = DirectionType.LEFT;
				else if(agl < pi_p * 11)
					dir = DirectionType.LEFT_UP;
				else if(agl < pi_p * 13)
					dir = DirectionType.UP;
				else if(agl <= pi_p * 15)
					dir = DirectionType.RIGHT_UP;
			}
			else if(directionMode == 2)
			{
				pi_p = Math.PI / 4;
				if(agl < Math.PI / 4 || agl > pi_p * 7)
					dir = DirectionType.RIGHT;							
				else if(agl < pi_p * 3)
					dir = DirectionType.DOWN;				
				else if(agl < pi_p * 5)
					dir = DirectionType.LEFT;				
				else if(agl <= pi_p * 7)
					dir = DirectionType.UP;				
			}
			
			return dir + initDir;
		}
		/**获取状态对应的角度
		 * @param dir		 
		 * @param initDir 初始角度
		 * @return 状态值	参考DirectionType常量
		*/
		public static getDirectorAngle(dir:number):number
		{
			return DirectionType.angleArray[dir];
		}
	}
}